<?php session_start();

if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{
	if(isset($_SESSION['type']))
	{
		if($_SESSION['type'] == 'administrator')
		{
			header('Location: admin_index.php');
			exit();
		}
		elseif($_SESSION['type'] == 'student')
		{
			header('Location: student_index.php');
			exit();
		}
		elseif($_SESSION['type'] == 'tutor')
		{
			header('Location: tutor_index.php');
			exit();
		}
		elseif($_SESSION['type'] == 'parent')
		{
			$host = 'localhost';
			$dbuser = 'postgres';
			$dbpass = 'password';
			$dbname = $_SESSION['database'];
			$username = $_SESSION['user'];
			
			pg_connect("host=$host user=$dbuser password=$dbpass dbname=$dbname") or die(pg_last_error());
			$sql = "SELECT * FROM users WHERE username = '$username';";
			$result = pg_query($sql);
			$firstname = pg_fetch_result($result, 0, 'firstname');
			$middlename = pg_fetch_result($result, 0, 'middlename');
			$lastname = pg_fetch_result($result, 0, 'lastname');
			?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Profile</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style>
.nav {
	width: 210px;
	height: auto;
	margin-left: 10px;
	text-align: center;
}

.mainline {
	width: 712px;
	height: auto;
	text-align: center;
}
</style>
</head>

<body bgcolor="#FFFFFF">
	<center>
		<div id="wrapper">
			<div id="header">
				<h1></h1>
			</div>

			<div id="header2">
				<h3></h3>
			</div>

			<div id="nav">
				<?php include 'parent_navigation.php';?>
			</div>

			<div id="mainline">
				<h4>Your Profile</h4>
			</div>

			<div id="body">
				<center>
					<table width="600">
						<tr bgcolor="e8e8e8">
							<td width="200"><b>Name:</b></td>
							<td width="400"><?php echo "$lastname, $firstname $middlename";?></td>
						</tr>

						<tr bgcolor="#f5f5f5">
							<td><b>Email:</b></td>
							<td><?php echo pg_fetch_result($result, 0, 'username');?></td>
						</tr>
						
						<tr bgcolor="e8e8e8">
							<td><b>Contact Number:</b></th>
							<td><?php echo pg_fetch_result($result, 0, 'contactnum')?></td>
						</tr>

						<tr bgcolor="#f5f5f5"> 
							<td><b>Street Address 1:</b></td>
							<td><?php echo pg_fetch_result($result, 0, 'streetadd1');?></td>
						</tr>

						<tr bgcolor="e8e8e8">
							<td><b>Street Address 2:<b></td>
							<td><?php echo pg_fetch_result($result, 0, 'streetadd2');?></td>
						</tr>

						<tr bgcolor="#f5f5f5">
							<td><b>City:</b></td>
							<td><?php echo pg_fetch_result($result, 0, 'cityadd');?></td>
						</tr>

					</table>
				</center>
			</div>

			<p align="justify">
				<br />
			</p>
		

		<br class="clearfloat"> <br />

		<div id="footer">
			<p align="center">
				Tutorial Business Manager: info@tbms.com <br />Credits/Engineers:
				Aquino, Chloebelle; Dela Cruz, Roy Erwin; Maliwanag, Ranyel Bryan;
				Manzano, Audrey Ann; Ng, Sheila Regine<br /> <br />copyright 2011
			</p>
		</div>
		</div>
	</center>
</body>
</html>
<?php

		}
	}
}
else
{
	header('Location: index.php');
}
?>
